<?php
/**
 * This file is a script to resize a image.
 *
 * located in the inc/template-tags.php file.
 * @package Edit Image Color
 */
?>
<?php

// Set this to true if you want to be able to load images from a url that doesn't
// end in an image file extension. E.g. through another proxy of kinds.
define('ALLOW_NO_EXT', false);
//resize width
$width = 0;
$height = 0;
//crop width
$cWidth = 0;
$cHeight = 0;
if (isset($_REQUEST['w'])) {
    $width = $_REQUEST['w'];
}
if (isset($_REQUEST['h'])) {
    $height = $_REQUEST['h'];
}
if (isset($_REQUEST['cw'])) {
    $cWidth = $_REQUEST['cw'];
}
if (isset($_REQUEST['ch'])) {
    $cHeight = $_REQUEST['ch'];
}
if (!$_GET['url']) {
    exit;
}
// Grab the URL
$url = trim(urldecode($_GET['url']));

$urlinfo = parse_url($url, PHP_URL_PATH);
$ext = array_reverse(explode(".", $urlinfo));

$ctype = null;
switch (strtolower($ext[0])) {
    case 'gif': $ctype = 'gif';
        break;
    case 'png': $ctype = 'png';
        break;
    case 'jpeg':
    case 'jpg': $ctype = 'jpg';
        break;
    default:
        if (ALLOW_NO_EXT) {
            $ctype = 'application/octet-stream';
        } else {
            exit;
        }
}
header("Content-Type: image/$ctype");
include ('resize-image.php');

$nImage = new ResizeImage();
if ($width != 0 || $height != 0) {
    $nImage->load($url);
    $nImage->resizeToHeight($height);
}
$nImage->output();